from typing import Any, Optional

from pydantic import BaseModel


class CommonResponse(BaseModel):
    code: int
    message: str
    data: Optional[Any] = None


def success(message: str = "成功", data: Any = None, ) -> CommonResponse:
    return CommonResponse(code=0, message=message, data=data)


def error(message: str = "失败", data: Any = None) -> CommonResponse:
    return CommonResponse(code=1, message=message, data=data)
